#ifndef M_CMD_H
#define M_CMD_H

#define PK_HEAD                         0xFB // 包头
#define PK_TAIL                         0xED // 包尾
#define PK_MIN                          0x0A // 包最小长度10
#define PK_MAX                          0xFF // 包最大长度255

#ifndef SOCKE_CMD_BUF_MAX
#define SOCKE_CMD_BUF_MAX               PK_MAX
#endif

/** 指令请求、响应类型 */
typedef enum {
    /** 请求 */
    M_CMD_REQ     = 0,
    /** 响应 */
    RES     = 1
} cmd_ack_type;

/** 指令类型 */
typedef enum {
    /** 透传 */
    PASS        = 0,
    /** 连接wifi */
    WIFI        = 1,
    /** 遥控 */
    ENJOY    = 2
} cmd_biz_type;

/** 透传类型 */
typedef enum {
    NOT     = 0,
    SPI     = 1,
    UART    = 2,
    I2C     = 3
} cmd_pass_type;

/** 透传线路 */
typedef enum {
    ROUTE0     = 0,
    ROUTE1     = 1,
    ROUTE2     = 2,
    ROUTE3     = 3,
    ROUTE4     = 4,
    ROUTE5     = 5,
    ROUTE6     = 6,
    ROUTE7     = 7
} cmd_pass_route;

/** 开关状态 */
typedef enum {
    OFF     = 0,
    ON      = 1
} cmd_switch_status;

/** <透传>指令业务内容 */
typedef struct {
    cmd_pass_type   type    :4;
    cmd_pass_route  route   :4;
    unsigned int    size;
    /** 透传内容 */
    unsigned char   *buf;
} cmd_req_pass;

/** <wifi连接>指令业务内容 */
typedef struct {
    /** WIFI SSID */
    char ssid[20];
    /** WIFI 密码 */
    char pwd[20];
} cmd_req_wifi;

/** <遥控>指令业务内容 */
typedef struct {
    cmd_switch_status left;
    cmd_switch_status right;
    cmd_switch_status up;
    cmd_switch_status down;
    cmd_switch_status a;
    cmd_switch_status b;
    cmd_switch_status c;
    cmd_switch_status d;
} cmd_req_enjoy;

/** 通用指令 */
typedef struct {
    cmd_ack_type ackType :1;
    cmd_biz_type bizType :8;
    unsigned int serialNo;
    union {
        cmd_req_pass   *pass;
        cmd_req_wifi   *wifi;
        cmd_req_enjoy  *enjoy;
    };
} command;

#endif // M_CMD_H